﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using AjaxPro;
using MSXML2;//xmlhttp
public partial class HTMLX : System.Web.UI.Page
{
    public XMLHTTPClass xmhttp = new XMLHTTPClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(HTMLX));
        Response.Write(Request.Url.Authority);
    }
    [AjaxMethod]
    public String xm(string url)
    {
        
        string txt="",filename="";//要写入的代码
        if (url != "")
        {
            //得到代码
            try
            {
                xmhttp.open("get", url, false, "", "");
                xmhttp.send(null);
                txt = xmhttp.responseText;
                xmhttp = null;

                filename = "CreateASPXfile/" + DateTime.Now.ToString().Replace("_", "").Replace(":","") + DateTime.Now.Millisecond.ToString() + ".aspx".Replace(" ","");//得到文件名
                //开始写入文件 不乱码的那种
                StreamWriter sw = new StreamWriter(Server.MapPath(filename), false, Encoding.UTF8);
                sw.Write(txt);//写文件
                sw.Flush();//清空缓存
                sw.Close();
                sw = null;
            }
            catch(Exception ex)
            {
                filename = ex.Message;
            }


        }
        return "ajaxpro/"+filename;
    }
}
